﻿/*-*-* Copyright (c) zouhangte@uframe
 * Author: zouhangte
 * Creation Date: 2024-08-20
 * Version: 1.0.0
 * Description: 
 *_*/

using System;
using UnityEngine;
using System.Collections.Generic;

namespace UFrame.StateTree 
{
    public abstract class StateBase : IState
    {
        public string Name { get; private set; }

        [SerializeReference]
        protected List<ICondition> conditions = new List<ICondition>();
        protected bool canExit;

        public StateBase(string name)
        {
            Name = name;
        }

        public abstract void Enter();
        public abstract void Execute();
        public abstract void Exit();

        public virtual IState CheckTransitions()
        {
            foreach (var condition in conditions)
            {
                if (condition.Evaluate())
                {
                    return condition.TargetState;
                }
            }
            return null;
        }

        public void AddCondition(ICondition condition)
        {
            conditions.Add(condition);
        }
    }

}

